/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_alumnoDAOImpl implements orm.dao.Trp_alumnoDAO {
	public Trp_alumno loadTrp_alumnoByORMID(String al_id_rut) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_alumnoByORMID(session, al_id_rut);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno getTrp_alumnoByORMID(String al_id_rut) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_alumnoByORMID(session, al_id_rut);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByORMID(String al_id_rut, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_alumnoByORMID(session, al_id_rut, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno getTrp_alumnoByORMID(String al_id_rut, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_alumnoByORMID(session, al_id_rut, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByORMID(PersistentSession session, String al_id_rut) throws PersistentException {
		try {
			return (Trp_alumno) session.load(orm.Trp_alumno.class, al_id_rut);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno getTrp_alumnoByORMID(PersistentSession session, String al_id_rut) throws PersistentException {
		try {
			return (Trp_alumno) session.get(orm.Trp_alumno.class, al_id_rut);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByORMID(PersistentSession session, String al_id_rut, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_alumno) session.load(orm.Trp_alumno.class, al_id_rut, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno getTrp_alumnoByORMID(PersistentSession session, String al_id_rut, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_alumno) session.get(orm.Trp_alumno.class, al_id_rut, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno[] listTrp_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno[] listTrp_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno[] listTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_alumno as Trp_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_alumno[]) list.toArray(new Trp_alumno[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno[] listTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_alumno as Trp_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_alumno[]) list.toArray(new Trp_alumno[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_alumno[] trp_alumnos = listTrp_alumnoByQuery(session, condition, orderBy);
		if (trp_alumnos != null && trp_alumnos.length > 0)
			return trp_alumnos[0];
		else
			return null;
	}
	
	public Trp_alumno loadTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_alumno[] trp_alumnos = listTrp_alumnoByQuery(session, condition, orderBy, lockMode);
		if (trp_alumnos != null && trp_alumnos.length > 0)
			return trp_alumnos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_alumno as Trp_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_alumno as Trp_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno createTrp_alumno() {
		return new orm.Trp_alumno();
	}
	
	public boolean save(orm.Trp_alumno trp_alumno) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_alumno trp_alumno) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_alumno trp_alumno)throws PersistentException {
		try {
			if(trp_alumno.getSexo_id_cod() != null) {
				trp_alumno.getSexo_id_cod().trp_alumno.remove(trp_alumno);
			}
			
			if(trp_alumno.getCurso() != null) {
				trp_alumno.getCurso().trp_alumno1.remove(trp_alumno);
			}
			
			orm.Trp_datos[] lTrp_datoss = trp_alumno.trp_datos.toArray();
			for(int i = 0; i < lTrp_datoss.length; i++) {
				lTrp_datoss[i].setAlumno_id_rut(null);
			}
			return delete(trp_alumno);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_alumno trp_alumno, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(trp_alumno.getSexo_id_cod() != null) {
				trp_alumno.getSexo_id_cod().trp_alumno.remove(trp_alumno);
			}
			
			if(trp_alumno.getCurso() != null) {
				trp_alumno.getCurso().trp_alumno1.remove(trp_alumno);
			}
			
			orm.Trp_datos[] lTrp_datoss = trp_alumno.trp_datos.toArray();
			for(int i = 0; i < lTrp_datoss.length; i++) {
				lTrp_datoss[i].setAlumno_id_rut(null);
			}
			try {
				session.delete(trp_alumno);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_alumno trp_alumno) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_alumno trp_alumno) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_alumno loadTrp_alumnoByCriteria(Trp_alumnoCriteria trp_alumnoCriteria) {
		Trp_alumno[] trp_alumnos = listTrp_alumnoByCriteria(trp_alumnoCriteria);
		if(trp_alumnos == null || trp_alumnos.length == 0) {
			return null;
		}
		return trp_alumnos[0];
	}
	
	public Trp_alumno[] listTrp_alumnoByCriteria(Trp_alumnoCriteria trp_alumnoCriteria) {
		return trp_alumnoCriteria.listTrp_alumno();
	}
}
